home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
fax
/
src
/
port
/
svr4
/
flock.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
626b
|
32 lines
/* flock emulation for System V using fcntl
*
* flock is just mapped to fcntl
*/
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "port.h"
int
flock(int fd, int operation)
{
struct flock flock;
int r;
memset(&flock, '\0', sizeof(flock));
if (operation & LOCK_EX)
flock.l_type = F_WRLCK;
else if (operation & LOCK_SH)
flock.l_type = F_RDLCK;
else
flock.l_type = F_UNLCK;
flock.l_whence = SEEK_SET;
if (((r=fcntl(fd, (operation & LOCK_NB) ? F_SETLK:F_SETLKW, &flock)) == -1)
&& (errno == EACCES || errno == EAGAIN))
errno = EWOULDBLOCK;
return r;
}